import request from '@/utils/request'

// ======================== 仪表板相关接口 ========================

// 获取核心统计数据
export function getCoreStats() {
  return request({
    url: '/credit/admin/stats/coreOpen',
    method: 'get'
  })
}

// 获取用户画像数据
export function getUserProfileData() {
  return request({
    url: '/credit/admin/stats/userProfileOpen',
    method: 'get'
  })
}

// 获取信用分分布数据
export function getCreditDistribution() {
  return request({
    url: '/credit/admin/stats/creditDistributionOpen',
    method: 'get'
  })
}

// 获取服务使用趋势数据
export function getServiceUsageTrend(timeRange) {
  return request({
    url: '/credit/admin/stats/usageTrendOpen',
    method: 'get',
    params: { timeRange }
  })
}

// 获取地区分布数据
export function getRegionDistribution() {
  return request({
    url: '/credit/admin/stats/regionDistributionOpen',
    method: 'get'
  })
}

// 获取收入统计数据
export function getRevenueStats(timeRange) {
  return request({
    url: '/credit/admin/stats/revenueOpen',
    method: 'get',
    params: { timeRange }
  })
}

// 获取详细统计数据
export function getDetailedStats(dateRange) {
  return request({
    url: '/credit/admin/stats/detailed',
    method: 'get',
    params: { dateRange }
  })
}

// ======================== 用户管理相关接口 ========================

// 查询用户列表
export function getUserList(query) {
  return request({
    url: '/credit/admin/users/list',
    method: 'get',
    params: query
  })
}

// 获取用户详情
export function getUserInfo(userId) {
  return request({
    url: `/credit/admin/users/detail/${userId}`,
    method: 'get'
  })
}

// 更新用户信息
export function updateUser(data) {
  return request({
    url: '/credit/admin/users/updateOpen',
    method: 'put',
    data: data
  })
}

// 删除用户
export function deleteUsers(userIds) {
  return request({
    url: `/credit/admin/users/deleteOpen/${userIds}`,
    method: 'delete'
  })
}

// 导出用户数据
export function exportUsers(query) {
  return request({
    url: '/credit/admin/users/export',
    method: 'post',
    data: query
  })
}

// 调整用户信用分
export function adjustUserScore(data) {
  return request({
    url: '/credit/admin/users/adjustScore',
    method: 'post',
    data: data
  })
}

// 批量调整用户信用分
export function batchAdjustUserScore(data) {
  return request({
    url: '/credit/admin/users/batchAdjustScore',
    method: 'post',
    data: data
  })
}

// 获取用户信用分变更历史
export function getUserScoreHistory(userId) {
  return request({
    url: `/credit/admin/users/${userId}/scoreHistory`,
    method: 'get'
  })
}

// 发送用户通知
export function sendUserNotification(data) {
  return request({
    url: '/credit/admin/users/sendNotification',
    method: 'post',
    data: data
  })
}

// 获取用户统计信息
export function getUserStatistics() {
  return request({
    url: '/credit/admin/users/statistics',
    method: 'get'
  })
}

// 新增用户
export function addUser(data) {
  return request({
    url: '/credit/admin/users/createOpen',
    method: 'post',
    data: data
  })
}

// 切换用户状态
export function toggleUserStatus(data) {
  return request({
    url: '/credit/admin/users/toggleStatus',
    method: 'post',
    data: data
  })
}

// ======================== 服务配置相关接口 ========================

// 查询服务配置列表
export function getServiceConfigList(query) {
  return request({
    url: '/credit/admin/services/list',
    method: 'get',
    params: query
  })
}

// 获取服务配置详情
export function getServiceConfig(configId) {
  return request({
    url: `/credit/admin/services/${configId}`,
    method: 'get'
  })
}

// 新增服务配置
export function addServiceConfig(data) {
  return request({
    url: '/credit/admin/services',
    method: 'post',
    data: data
  })
}

// 修改服务配置
export function updateServiceConfig(data) {
  return request({
    url: '/credit/admin/services',
    method: 'put',
    data: data
  })
}

// 删除服务配置
export function delServiceConfig(configIds) {
  return request({
    url: `/credit/admin/services/${configIds}`,
    method: 'delete'
  })
}

// 批量更新服务状态
export function batchUpdateServiceStatus(data) {
  return request({
    url: '/credit/admin/services/batchStatus',
    method: 'post',
    data: data
  })
}

// 导出服务配置
export function exportServiceConfig(query) {
  return request({
    url: '/credit/admin/services/export',
    method: 'post',
    data: query
  })
}

// 获取服务使用统计
export function getServiceUsageStats() {
  return request({
    url: '/credit/admin/services/usageStats',
    method: 'get'
  })
}

// ======================== 信用员服务配置相关接口（无需权限） ========================

// 信用员查询服务配置列表
export function getServiceConfigListOpen(query) {
  return request({
    url: '/credit/admin/services/listOpen',
    method: 'get',
    params: query
  })
}

// 信用员获取服务配置详情
export function getServiceConfigOpen(configId) {
  return request({
    url: `/credit/admin/services/detail/${configId}`,
    method: 'get'
  })
}

// 信用员新增服务配置
export function addServiceConfigOpen(data) {
  return request({
    url: '/credit/admin/services/addOpen',
    method: 'post',
    data: data
  })
}

// 信用员修改服务配置
export function updateServiceConfigOpen(data) {
  return request({
    url: '/credit/admin/services/editOpen',
    method: 'put',
    data: data
  })
}

// 信用员删除服务配置
export function delServiceConfigOpen(configIds) {
  return request({
    url: `/credit/admin/services/deleteOpen/${configIds}`,
    method: 'delete'
  })
}

// 信用员批量更新服务状态
export function batchUpdateServiceStatusOpen(data) {
  return request({
    url: '/credit/admin/services/batchStatusOpen',
    method: 'post',
    data: data
  })
}

// ======================== 新闻管理相关接口 ========================

// 查询新闻列表
export function getNewsList(query) {
  return request({
    url: '/credit/admin/news/listOpen',
    method: 'get',
    params: query
  })
}

// 获取新闻详情
export function getNews(newsId) {
  return request({
    url: `/credit/admin/news/detail/${newsId}`,
    method: 'get'
  })
}

// 新增新闻
export function addNews(data) {
  return request({
    url: '/credit/admin/news/addOpen',
    method: 'post',
    data: data
  })
}

// 修改新闻
export function updateNews(data) {
  return request({
    url: '/credit/admin/news/editOpen',
    method: 'put',
    data: data
  })
}

// 删除新闻
export function delNews(newsIds) {
  return request({
    url: `/credit/admin/news/deleteOpen/${newsIds}`,
    method: 'delete'
  })
}

// 批量发布新闻
export function batchPublishNews(data) {
  return request({
    url: '/credit/admin/news/batchPublishOpen',
    method: 'post',
    data: data
  })
}

// 设置新闻置顶
export function setNewsTop(data) {
  return request({
    url: '/credit/admin/news/setTopOpen',
    method: 'post',
    data: data
  })
}

// 导出新闻列表
export function exportNews(query) {
  return request({
    url: '/credit/admin/news/export',
    method: 'post',
    data: query
  })
}

// 获取新闻统计信息
export function getNewsStatistics() {
  return request({
    url: '/credit/admin/news/statistics',
    method: 'get'
  })
}

// ======================== 通知管理相关接口 ========================

// 发送系统通知
export function sendSystemNotification(data) {
  return request({
    url: '/credit/admin/notification/send',
    method: 'post',
    data: data
  })
}

// 发送批量通知
export function sendBatchNotification(userIds, title, content) {
  return request({
    url: '/credit/admin/notification/batchSend',
    method: 'post',
    data: { userIds, title, content }
  })
}

// 获取通知发送历史
export function getNotificationHistory(query) {
  return request({
    url: '/credit/admin/notification/history',
    method: 'get',
    params: query
  })
}

// ======================== 数据分析相关接口 ========================

// 获取用户行为分析
export function getUserBehaviorAnalysis(query) {
  return request({
    url: '/credit/admin/stats/userBehavior',
    method: 'get',
    params: query
  })
}

// 获取服务使用分析
export function getServiceUsageAnalysis(query) {
  return request({
    url: '/credit/admin/stats/serviceUsage',
    method: 'get',
    params: query
  })
}

// 获取信用分趋势分析
export function getCreditScoreTrend(query) {
  return request({
    url: '/credit/admin/stats/creditTrend',
    method: 'get',
    params: query
  })
}

// 获取异常数据
export function getAnomalyData(query) {
  return request({
    url: '/credit/admin/stats/anomalies',
    method: 'get',
    params: query
  })
}

// ======================== 系统管理相关接口 ========================

// 获取系统配置
export function getSystemConfig() {
  return request({
    url: '/credit/admin/system/config',
    method: 'get'
  })
}

// 更新系统配置
export function updateSystemConfig(data) {
  return request({
    url: '/credit/admin/system/config',
    method: 'put',
    data: data
  })
}

// 清理系统缓存
export function clearSystemCache() {
  return request({
    url: '/credit/admin/system/cache/clear',
    method: 'post'
  })
}

// 获取系统日志
export function getSystemLogs(query) {
  return request({
    url: '/credit/admin/system/logs',
    method: 'get',
    params: query
  })
}

// 导出系统日志
export function exportSystemLogs(query) {
  return request({
    url: '/credit/admin/system/logs/export',
    method: 'post',
    data: query,
    responseType: 'blob'
  })
}

// ======================== 权限管理相关接口 ========================

// 获取管理员列表
export function getAdminList(query) {
  return request({
    url: '/credit/admin/admins/list',
    method: 'get',
    params: query
  })
}

// 添加管理员
export function addAdmin(data) {
  return request({
    url: '/credit/admin/admins',
    method: 'post',
    data: data
  })
}

// 更新管理员信息
export function updateAdmin(data) {
  return request({
    url: '/credit/admin/admins',
    method: 'put',
    data: data
  })
}

// 删除管理员
export function delAdmin(adminIds) {
  return request({
    url: `/credit/admin/admins/${adminIds}`,
    method: 'delete'
  })
}

// 重置管理员密码
export function resetAdminPassword(adminId, newPassword) {
  return request({
    url: `/credit/admin/admins/${adminId}/resetPassword`,
    method: 'put',
    data: { newPassword }
  })
}

// 更新管理员状态
export function updateAdminStatus(adminId, status) {
  return request({
    url: `/credit/admin/admins/${adminId}/status`,
    method: 'put',
    data: { status }
  })
} 